<?php
/**
 * Description: 今日好物-列表
 * Created by PhpStorm.
 * User: congyukun
 * Date: 2021/9/29
 * Time: 15:34
 */


use Biz\cache\brand\BlindBox;
use Biz\service\TodayNiceGoods\TodayNIceGoodsService;
use Doraemon\tools\Hhzurl;
use Doraemon\service\statSign\Basic as basicStatSign;
use Doraemon\pockets\constInterface\statSign\Module;


class ListAction extends ActionPlugin
{
    public const USER_LEVEL = self::LEVEL_REGISTER;

    /**
     * 获取活动列表
     * @throws Exception
     */
    public function main()
    {
        $uid = $this->uid;
        $url = Hhzurl::getDomain() . '/brand/former-days-goods?hhzjump=1';
        $data = [
            'list' => [],
            'before_list_link' => ''
        ];
        //获取 想要的字段
        $field = [
            'brand_id',
//            'brand_name',
            'basic_id',
            'wiki_id',
            'img',
            "back_img",
            "back_show_img",
            'title',
            'sec_title',
            'tags',
            'sort',
            'start_at',
            'end_at',
            'status',
        ];
        $uids = BlindBox::get(BlindBox::TODAY_NICE_GOODS_WHITE_USERS);
        $uids = $uids ? explode(",", $uids) : [];
        $is_show_all = false;
        if (in_array($uid, $uids)) {
            $is_show_all = true;
        }
        $list = TodayNIceGoodsService::getRecentActLists($field, TodayNIceGoodsService::ACT_NUM, $is_show_all);
        if (!$list) {
            return $this->setSuccess($data);
        }

        foreach ($list as &$item) {
            $middleLink = $item['wiki_id'] ? Hhzurl::H5WikiMiddleList($item['wiki_id']) : '';
            // 客户端根据返回的数据有 middle_link  字段 就是用这个短链跳转，如果这个字段为空或者没有，就按wikiID 跳转详情
            if(version_compare(\Doraemon\tools\HhzClient::getClientVersion(), '5.24.0', ">=")){
                $item['middle_link'] = '';
            }else{
                $item['middle_link'] = \Biz\tools\helper\Common::formatFullScreenLink($middleLink);
            }
            $item['statSign'] = basicStatSign::genStatSign(Module::MODULE_TODAY_NICE_GOODS_LIST, [],
                [
                    'wiki_id' => $item['wiki_id'],
                    'basic_id' => $item['basic_id'],
                    'uid' => $uid,
                    'act_from' => 'today_nice_goods'
                ]);
        }
        $data['list'] = TodayNIceGoodsService::formatList($list);
        $data['list'] = \Doraemon\tools\StatSign::versionCompatible($data['list'], \Doraemon\tools\StatSign::BRAND_UP_GRADE_VERSION_521, \Doraemon\tools\BlockType::TYPE_TODAY_NICE_GOODS, 'today_goods_info' );
        $data['before_list_link'] = \Biz\tools\helper\Common::formatLinkNormalLink($url);
        return $this->setSuccess($data);
    }

}